<?
/*! \brief Simple authentication agent. 
 * 
 */
class Auth
{	
	/*! \brief Checks the database for a supplied username and password.
	 * 
	 * \param username plain text username
	 * \param password plain text password
	 * \return boolean
	 */
	public static function authenticate($username=null, $password=null)
	{
		$db = Zend_Registry::get('db');
		
		if($db == null)
		{
			Logger::file()->err('Cannot authenticate: database is null');
			return false;
		}
		
		
		if($username == null || $password == null)
		{
			Logger::file()->err('Cannot authenticate: username or password '. 
				'is null');
			return false;
		}
		
		//Create password hash
		$password = md5($password);
		
		//Check for user in database	
		$sql = 'SELECT * FROM `login` WHERE `username`= ? AND `password` = ?';
		$result = $db->query($sql, array($username, $password));
		$db->setFetchMode(Zend_Db::FETCH_OBJ);
		$result = $result->fetchAll();
		
		if(sizeof($result) > 0)
			return true;
		else
			return false;
	}
}